import asyncio
import re
from playwright.async_api import Playwright, async_playwright, expect


async def run(playwright: Playwright) -> None:
    browser = await playwright.chromium.launch(headless=False)
    context = await browser.new_context()
    page = await context.new_page()
    await page.goto("http://192.168.10.1/")
    await page.get_by_role("button", name="OK").click()
    await page.get_by_role("link", name="Settings", exact=True).click()
    await page.get_by_role("button", name="OK").click()
    await page.get_by_label("Password").click()
    await page.get_by_label("Password").fill("admin123")
    await page.get_by_label("Password").press("Enter")
    await page.get_by_role("link", name="Mobile Network").click()
    await page.get_by_role("link", name="APN").click()
    await page.get_by_role("button", name="Add").click()
    await page.get_by_role("textbox").first.click()
    await page.get_by_role("textbox").first.fill("11")
    await page.get_by_role("textbox").nth(1).click()
    await page.get_by_role("textbox").nth(1).fill("111")
    await page.get_by_role("textbox").nth(2).click()
    await page.get_by_role("textbox").nth(2).fill("1")
    await page.get_by_role("cell", name="1", exact=True).get_by_role("textbox").fill("11")
    await page.get_by_role("textbox").nth(3).click()
    await page.get_by_role("textbox").nth(3).fill("11")
    await page.get_by_text("OK").click()
    await page.get_by_role("button", name="Add").click()
    await page.get_by_role("textbox").nth(1).click()
    await page.get_by_role("textbox").nth(1).fill("22")
    await page.get_by_role("textbox").nth(2).click()
    await page.get_by_role("textbox").nth(2).fill("2")
    await page.get_by_role("textbox").nth(3).click()
    await page.get_by_role("textbox").nth(3).fill("22")
    await page.get_by_role("row", name="222 2 22 None IPv4 OK Cancel").get_by_role("combobox").nth(1).select_option("1")
    await page.get_by_text("OK").click()
    await page.get_by_role("button", name="Add").click()
    await page.get_by_role("textbox").first.fill("33")
    await page.get_by_role("textbox").nth(1).click()
    await page.get_by_role("textbox").nth(1).fill("33")
    await page.get_by_role("row", name="33 None IPv4 OK Cancel").get_by_role("combobox").nth(1).select_option("2")
    await page.get_by_text("OK").click()
    await page.get_by_role("button", name="Add").click()
    await page.get_by_role("button", name="OK").click()
    await page.get_by_role("button", name="Add").click()
    await page.get_by_role("button", name="OK").click()
    await page.get_by_role("button", name="Add").click()
    await page.get_by_role("button", name="OK").click()
    await page.get_by_role("row", name="111 11 11 None IPv4 Edit Delete").get_by_role("radio").check()
    await page.get_by_role("row", name="11 None IPv4 Edit Delete").locator("div").nth(2).click()
    await page.get_by_role("button", name="OK").click()

    # ---------------------
    await context.close()
    await browser.close()


async def main() -> None:
    async with async_playwright() as playwright:
        await run(playwright)


asyncio.run(main())
